package com.baize.baizeapp.test.jetpack

import android.os.AsyncTask
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class TestViewModel() : ViewModel() {
    var userLiveData: MutableLiveData<String> = MutableLiveData()
    var loadingLiveData: MutableLiveData<Boolean> = MutableLiveData()

    fun getUserInfo() {
        loadingLiveData.value = true

        object : AsyncTask<Unit, Unit, String>() {

            override fun onPostExecute(result: String) {
                //请求返回
                loadingLiveData.value = false
                userLiveData.value = result
            }

            override fun doInBackground(vararg params: Unit?): String {
                //延迟两秒
                Thread.sleep(2000)
                return "白泽........"
            }
        }.execute()
    }

}